package Tax_DAO;

import java.sql.Date;

import Codes_DAO.CodeValueDAO;
import Codes_DAO.CodeValueDB;

import com.mva.common.DAOFactory;
import com.mva.common.DataDictionaryConstants;
import com.mva.common.DateUtils;
import com.mva.common.Displayable;
import com.mva.common.StringUtils;

/*******************************************************************************
 The <big><b>Tax</b></big> class implements the <b>Displayable</b> &
 <b>Cloneable</b> interfaces to create a <b>Tax</b> object
 <br><br>
 @author z049984 - 1:33:38 PM - Aug 22, 2011
 <br><br>
 @version 1.2  
 *******************************************************************************/
public class Tax implements Displayable, Cloneable, DataDictionaryConstants
  {
   private String State;
   private String County;
   private String City;
   private Date   Dt_Eff;
   private double Rt;
   
   // Declare a class variable
   private static CodeValueDAO codevalueDAO = null;

   /*******************************************************************************
	This constructor creates a new <b>Tax</b> object with default values
   *******************************************************************************/
   public Tax ()
	 {
	  this.State  = "UT";
	  this.County = " ";
	  this.City   = " ";
	  this.Dt_Eff = Date.valueOf("1990-01-01");
	  this.Rt     = 0.0000;
	 }

   /*******************************************************************************
	This constructor creates a new <b>Tax</b> object with attribute values as
	defined by the provided parameters
	<br><br>
	@param State A <b><i>String</i></b> variable
	@param County A <b><i>String</i></b> variable
	@param City A <b><i>String</i></b> variable
	@param Date - effective A <b><i>Date</i></b> variable
	@param Rate A <b><i>double</i></b> variable
   *******************************************************************************/
   public Tax (String State, String County, String City, Date Dt_Eff, double Rt)
	 {
	  this.State  = State;
	  this.County = County;
	  this.City   = City;
	  this.Dt_Eff = Dt_Eff;
	  this.Rt     = Rt;
	 }

   /*******************************************************************************
	Clones a current <b>Tax</b> object to create a new one
	<br><br>
	@return Tax - A <b>Tax</b> object
	@throws CloneNotSupportedException 
   *******************************************************************************/
   public Object clone () throws CloneNotSupportedException
	 {
	  return super.clone();
	 }

   /*******************************************************************************
	Sets the <b><i>String</i></b> <b>State</b> attribute for the current <b>Tax</b>
	object
	<br><br>
	The value must be uppercase, trimmed, left-justified, & exist in the cd_val
	table in the MVA/ST segment
	<br><br>
	@param State A <b><i>String</i></b> variable
	@return Success/failure - A <b><i>boolean</i></b> variable
   *******************************************************************************/
   public boolean setState (String state)
	 {
	  String tmpSt       = state.trim();
	         tmpSt       = tmpSt.toUpperCase();
	  codevalueDAO       = DAOFactory.getCodeValueDAO();
      CodeValueDAO cvDAO = new CodeValueDB();
      boolean isValid    = cvDAO.existsCode("MVA", "ST", tmpSt);
      if (isValid)
	    {
	     this.State      = tmpSt;
	     return true;
	    }
	  else
	    {
	     return false;
	    }
	 }

   /*******************************************************************************
	Retrieves the <b><i>String</i></b> <b>State</b> attribute from the current
	<b>Tax</b> object
	<br><br>
	@return State - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String getState ()
	 {
	  return State;
	 }

   /*******************************************************************************
	Sets the <b><i>String</i></b> <b>County</b> attribute for the current
	<b>Tax</b> object
	<br><br>
	The value must be uppercase, trimmed, left-justified, & exist in the cd_val
	table in the MVA/CNTY segment
	<br><br>
	@param County A <b><i>String</i></b> variable
	@return Success/failure - A <b><i>boolean</i></b> variable
   *******************************************************************************/
   public boolean setCounty (String county)
	 {
	  String tmpCnty     = county.trim();
	         tmpCnty     = tmpCnty.toUpperCase();
	  codevalueDAO       = DAOFactory.getCodeValueDAO();
      CodeValueDAO cvDAO = new CodeValueDB();
      boolean isValid    = cvDAO.existsCode("MVA", "CNTY", tmpCnty);
      if (isValid)
	    {
	     this.County     = tmpCnty;
	     return true;
	    }
	  else
	    {
	     return false;
	    }
	 }

   /*******************************************************************************
	Retrieves the <b><i>String</i></b> <b>County</b> attribute from the current
	<b>Tax</b> object
	<br><br>
	@return County - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String getCounty ()
	 {
	  return County;
	 }

   /*******************************************************************************
	Sets the <b><i>String</i></b> <b>City</b> attribute for the current	<b>Tax</b>
	object
	<br><br>
	The value must be uppercase, trimmed, left-justified, & exist in the cd_val
	table in the MVA/CTY segment
	<br><br>
	@param City A <b><i>String</i></b> variable
	@return Success/failure - A <b><i>boolean</i></b> variable
   *******************************************************************************/
   public boolean setCity (String city)
	 {
	  String tmpCty      = city.trim();
	         tmpCty      = tmpCty.toUpperCase();
	  codevalueDAO       = DAOFactory.getCodeValueDAO();
      CodeValueDAO cvDAO = new CodeValueDB();
      boolean isValid    = cvDAO.existsCode("MVA", "CTY", tmpCty);
      if (isValid)
	    {
	     this.City       = tmpCty;
	     return true;
	    }
	  else
	    {
	     return false;
	    }
	 }

   /*******************************************************************************
	Retrieves the <b><i>String</i></b> <b>City</b> attribute from the current
	<b>Tax</b> object
	<br><br>
	@return City - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String getCity ()
	 {
	  return City;
	 }

   /*******************************************************************************
	Sets the <b><i>Date</i></b> <b>Dt_Eff</b> attribute for the current <b>Tax</b>
	object
	<br><br>
	The value must be a valid date format - YYYY-MM-DD
	<br><br>
	@param Dt_Eff A <b><i>Date</i></b> variable
	@return Success/failure - A <b><i>boolean</i></b> variable
   *******************************************************************************/
   public boolean setDtEff (Date dt)
	 {
      boolean isValid    = true;
      if (isValid)
	    {
	     this.Dt_Eff = dt;
	     return true;
	    }
	  else
	    {
	     return false;
	    }
	 }

   /*******************************************************************************
	Retrieves the <b><i>Date</i></b> <b>Dt_Eff</b> attribute from the current
	<b>Tax</b> object
	<br><br>
	@return Dt_Eff - A <b><i>Date</i></b> variable
   *******************************************************************************/
   public Date getDtEff ()
	 {
	  return Dt_Eff;
	 }

   /*******************************************************************************
	Sets the <b><i>double</i></b> <b>Rt</b> attribute for the current <b>Tax</b>
	object
	<br><br>
	The value must be a positive value between 0.0000 & 0.9999
	<br><br>
	@param Rt A <b><i>double</i></b> variable
	@return Success/failure - A <b><i>boolean</i></b> variable
   *******************************************************************************/
   public boolean setRt (double rt)
	 {
      boolean isValid    = true;
      if (isValid)
	    {
	     this.Rt = rt;
	     return true;
	    }
	  else
	    {
	     return false;
	    }
	 }

   /*******************************************************************************
	Retrieves the <b><i>double</i></b> <b>Rt</b> attribute from the current
	<b>Tax</b> object
	<br><br>
	@return Rt - A <b><i>double</i></b> variable
   *******************************************************************************/
   public double getRt ()
	 {
	  return Rt;
	 }
   
   /*******************************************************************************
	Determines whether or not all of the attribute values of one <b>Tax</b>
	object are equal to all of the attribute values of a second <b>Tax</b>
	object
	@param object A	<b>Tax</b> object
	@return true/false - A <b><i>boolean</i></b> variable
   *******************************************************************************/
   public boolean equals (Object object)
     {
      if (object instanceof Tax)
        {
         Tax tax2 = (Tax) object;
         if (State.equals(tax2.getState())     &&
             County.equals(tax2.getCounty())  &&
             City.equals(tax2.getCity())  &&
             Dt_Eff.equals(tax2.getDtEff())  &&
             Rt == tax2.getRt())
         return true;
        }
      return false;
     }

   /*******************************************************************************
	Retrieves a one-line formatted list of the attribute values of the current
	<b>Tax</b> object for use in a table display
	@return string - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String toTableString ()
	 {
	  Double tmpRt = this.Rt;
	  return StringUtils.padWithSpaces(this.State,             State_LEN)    + " | " +
	         StringUtils.padWithSpaces(this.County,            Cnty_LEN)     + " | " +
	         StringUtils.padWithSpaces(this.City,              City_LEN)     + " | " +
	         StringUtils.padWithSpaces(DateUtils.strDt(this.Dt_Eff), Dt_LEN) + " | " +
	         StringUtils.padWithSpaces(tmpRt.toString(),       Rt_LEN);
	 }
   
   /*******************************************************************************
	Retrieves a formatted list of the attribute values of the current <b>Tax</b>
	object
	@return string - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String toString()
	 {
	  Double tmpRt = this.Rt;
	  return "State         : " + this.State                   + "\n" +
	         "County        : " + this.County                  + "\n" +
		     "City          : " + this.City                    + "\n" +
		     "Effective Date: " + DateUtils.strDt(this.Dt_Eff) + "\n" +
             "Rate          : " + tmpRt.toString()             + "\n";
	 }
   
   /*******************************************************************************
	Retrieves a formatted displayable list of the attribute values of the current
	<b>Tax</b> object
	@return string - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String getDisplayText()
    {
	  return toString();
    }
  }
